/*    */ package com.mbl.phone.controller;
/*    */ 
/*    */ import com.mbl.phone.service.UserService;
/*    */ import com.mbl.phone.utility.ResultUtil;
/*    */ import javax.annotation.Resource;
/*    */ import javax.servlet.http.HttpServletRequest;
/*    */ import net.sf.json.JSONObject;
/*    */ import org.apache.shiro.SecurityUtils;
/*    */ import org.apache.shiro.authc.DisabledAccountException;
/*    */ import org.apache.shiro.authc.ExcessiveAttemptsException;
/*    */ import org.apache.shiro.authc.ExpiredCredentialsException;
/*    */ import org.apache.shiro.authc.IncorrectCredentialsException;
/*    */ import org.apache.shiro.authc.LockedAccountException;
/*    */ import org.apache.shiro.authc.UnknownAccountException;
/*    */ import org.apache.shiro.authc.UsernamePasswordToken;
/*    */ import org.apache.shiro.authz.UnauthorizedException;
/*    */ import org.apache.shiro.subject.Subject;
/*    */ import org.slf4j.Logger;
/*    */ import org.slf4j.LoggerFactory;
/*    */ import org.springframework.stereotype.Controller;
/*    */ import org.springframework.web.bind.annotation.RequestMapping;
/*    */ import org.springframework.web.bind.annotation.ResponseBody;
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ @Controller
/*    */ public class UserController
/*    */ {
/* 35 */   static final Logger logger = LoggerFactory.getLogger(UserController.class);
/*    */   
/*    */   @Resource
/*    */   UserService userService;
/*    */   
/*    */   @Resource
/*    */   ResultUtil reSult;
/*    */   
/*    */   @RequestMapping(value={"/doLogin"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
/*    */   @ResponseBody
/*    */   public JSONObject login(HttpServletRequest req)
/*    */   {
/* 47 */     String username = req.getParameter("u");
/* 48 */     String password = req.getParameter("p");
/*    */     
/* 50 */     UsernamePasswordToken token = new UsernamePasswordToken(username, password);
/* 51 */     Subject subject = SecurityUtils.getSubject();
/*    */     try
/*    */     {
/* 54 */       subject.login(token);
/* 55 */       this.reSult.C_SUCCESS().D_SET("index.html");
/*    */     }
/*    */     catch (UnknownAccountException e) {
/* 58 */       this.reSult.C_ERROR().M_ERROR("帐号不存在");
/*    */     } catch (IncorrectCredentialsException e) {
/* 60 */       this.reSult.C_ERROR().M_ERROR("登录密码错误");
/*    */     } catch (ExcessiveAttemptsException e) {
/* 62 */       this.reSult.C_ERROR().M_ERROR("登录失败次数过多");
/*    */     } catch (LockedAccountException e) {
/* 64 */       this.reSult.C_ERROR().M_ERROR("帐号已被锁定");
/*    */     } catch (DisabledAccountException e) {
/* 66 */       this.reSult.C_ERROR().M_ERROR("帐号已被禁用");
/*    */     } catch (ExpiredCredentialsException e) {
/* 68 */       this.reSult.C_ERROR().M_ERROR("帐号已过期");
/*    */     } catch (UnauthorizedException e) {
/* 70 */       this.reSult.C_ERROR().D_PERMISSION();
/*    */     }
/*    */     
/* 73 */     return this.reSult.getInstance();
/*    */   }
/*    */   
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */   @RequestMapping(value={"/modifPassword"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
/*    */   @ResponseBody
/*    */   public JSONObject modifPassword(HttpServletRequest req)
/*    */   {
/* 84 */     String oldPaw = req.getParameter("o");
/* 85 */     String newPaw = req.getParameter("n");
/* 86 */     Integer modifyUser = this.userService.modifyUser(oldPaw, newPaw);
/*    */     
/* 88 */     if (modifyUser.intValue() == 1) {
/* 89 */       this.reSult.SUCCESS(modifyUser);
/*    */     } else {
/* 91 */       this.reSult.ERROR().D_SET(modifyUser);
/*    */     }
/*    */     
/* 94 */     return this.reSult.getInstance();
/*    */   }
/*    */ }


/* Location:              C:\Users\Administrator\Desktop\phone.war!\WEB-INF\classes\com\mbl\phone\controller\UserController.class
 * Java compiler version: 8 (52.0)
 * JD-Core Version:       0.7.1
 */